const state = {
  token: localStorage.getItem('token') || '',
  // username: localStorage.getItem('username') || '',
  // role: localStorage.getItem('role') || ''
}

const mutations = {
  SET_TOKEN (state, token) {
    state.token = token
    localStorage.setItem('token', token)
  },
  CLEAR_TOKEN (state) {
    state.token = ''
    localStorage.removeItem('token')
  },
  // SET_USERNAME (state, name) {
  //   state.username = name
  //   localStorage.setItem('username', name)
  // },
  // SET_ROLE(state, role) {
  //   state.role = role
  //   localStorage.setItem('role', role)
  // }
}

const actions = {
  login ({ commit }, { token, username, role }) {
    commit('SET_TOKEN', token)
    // commit('SET_USERNAME', username)
    // commit('SET_ROLE', role)
  },
  logout ({ commit }) {
    commit('CLEAR_TOKEN')
    // commit('SET_USERNAME', '')
    // commit('SET_ROLE', '')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
